package org.softmed.action.tree;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.softmed.action.Action;


public class ParentNode implements Node {

	Map<String, Node> children = new HashMap<String, Node>();

	public Map<String, Node> getChildren() {
		return children;
	}

	public void addAction(String name, Action action) {
		ActionContainerNode acn = new ActionContainerNode();
		acn.setAction(action);
		children.put(name, acn);
	}

	public void addParent(String name, String author) {
		ParentNode node = new ParentNode();
		children.put(name, node);
	}

	public void removeNode(Node node) {
		children.remove(node);
	}

	@Override
	public void dispose() {
		Collection<Node> values = children.values();
		for (Node node : values) {
			node.dispose();
		}
		children.clear();
	}

	@Override
	public Node getClone() throws Throwable {

		ParentNode clone = new ParentNode();

		Node node = null;
		Set<String> keys = children.keySet();
		for (String key : keys) {
			node = children.get(key);
			clone.getChildren().put(""+key, node.getClone());
		}

		return clone;
	}

	@Override
	public void rebuildPools() throws Throwable {
		Collection<Node> values = children.values();
		for (Node node : values) {
			node.rebuildPools();
		}

	}

	@Override
	public void setPoolIncrementSize(int size) {
		Collection<Node> values = children.values();
		for (Node node : values) {
			node.setPoolIncrementSize(size);
		}
	}

	@Override
	public void setPoolStartSize(int size) {
		Collection<Node> values = children.values();
		for (Node node : values) {
			node.setPoolStartSize(size);
		}

	}

}
